package orderoid.soap.business;

import orderoid.soap.Tool.DeserialisationTool;
import orderoid.soap.classeCommune.Adresse;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.AsyncTask;
import android.util.Log;

public class webServiceRecuperationAdresseClient extends AsyncTask<String, Void, Adresse> {

	private static final String PARAM_IDCLIENT = "idClient";
	
	@Override
	protected Adresse doInBackground(String... params) {
		Log.e("Test", "doInBackground : WebService recupération adresse d'un client");
		
		String idClient = params[0];
    			SoapObject request = new SoapObject(
				orderoid.soap.constant.method.NAMESPACE,
				orderoid.soap.constant.method.METHOD_NAME_GETADRESSE);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);

		envelope.setOutputSoapObject(request);

		HttpTransportSE androidHttpTransport = new HttpTransportSE(
				orderoid.soap.constant.method.URL);

		request.addProperty(PARAM_IDCLIENT, idClient);
		
		Adresse adresse = new Adresse();
		try {
			androidHttpTransport.call(
					orderoid.soap.constant.method.SOAP_ACTION_GETADRESSE,
					envelope);

			SoapObject soapObjectResp = (SoapObject) envelope.getResponse();

			adresse = DeserialisationTool.deserialisationAdresse(soapObjectResp);

		} catch (Exception e) {
			Log.e("Erreur", e.getMessage());
			adresse = null;
		}
		return adresse;
	}

}
